package wikiPhilia_3;

import processing.core.PApplet;

public class WEdge {
	public static final int TYPE_CONTAINS = 0;
	public static final int TYPE_LINKSTO = 1;
	public static final int TYPE_LOOP = 2;
	public static final int TYPE_UNDEF = 3;
	public static final int TYPE_LOOP_WITH_PZERO = 4;
	public static final int STATE_DEFAULT = 0;
	public static final int STATE_HIGHLIGHTED = 1;
	public static final int STATE_SELECTED = 2;
	private int state = STATE_DEFAULT;
	private PApplet parent;
	private WNode fromNode, toNode;
	private int type;
	private float myAlpha = 63;
	
	public WEdge (PApplet parent, WNode fromNode, WNode toNode) {
		this.parent = parent;
		this.fromNode = fromNode;
		this.toNode = toNode;
		this.type = TYPE_UNDEF;
	}

	public WEdge (PApplet parent, WNode fromNode, WNode toNode, int type) {
		this.parent = parent;
		this.fromNode = fromNode;
		this.toNode = toNode;
		this.type = type;
	}
	
	public void display() {
		//myAlpha = (getFromNode().getLinksCount()+getToNode().getLinksCount())*0.5f/(float)WikiPhilia_005.maxLinkCount*127f;
		parent.pushStyle();
		parent.strokeWeight(0.5f);
		switch (type) {
		case TYPE_UNDEF:
			parent.noStroke(); 
			//parent.stroke(parent.color(255,0,0,0));
			parent.beginShape();
			parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
			parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
			parent.endShape();
			switch (state) {
			case STATE_DEFAULT:
				parent.stroke(parent.color(50, 90, 20)); 
//				parent.stroke(parent.color(255,myAlpha));
//				parent.beginShape();
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
				break;
			case STATE_HIGHLIGHTED:
//				parent.strokeWeight(2f);
//				parent.stroke(parent.color(255,255,0,191));
//				parent.beginShape();
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
				break;
			case STATE_SELECTED:
				parent.strokeWeight(4f);
				parent.stroke(parent.color(0, 255, 0 ));
				parent.beginShape();
				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
				parent.endShape();
				break;

			default:
				break;
			}
			break;
		case TYPE_LOOP:

			switch (state) {
			case STATE_DEFAULT:
				parent.strokeWeight(1f);
				parent.stroke(parent.color(255,255,0, 120));
				parent.beginShape();
				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
				parent.endShape();
				break;
//			case STATE_HIGHLIGHTED:
//				parent.strokeWeight(3f);
//				parent.stroke(parent.color(255,0,0));
//				parent.beginShape();
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
//				break;
//			case STATE_SELECTED:
//				parent.strokeWeight(6f);
//				parent.stroke(parent.color(255,0,0));
//				parent.beginShape();
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
//				break;

			default:
				break;
			}
			
			
			
			break;
		case TYPE_CONTAINS: //category

			switch (state) {
			case STATE_DEFAULT:
//				parent.strokeWeight(1f);
//				parent.beginShape();
//				parent.stroke(parent.color(255, 15));
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				//parent.stroke(parent.color(255,255,0,63));
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
				break;
			case STATE_HIGHLIGHTED:
//				parent.strokeWeight(3f);
//				parent.stroke(parent.color(255,2,7,191));
//				parent.beginShape();
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
				break;
			case STATE_SELECTED:
//				parent.strokeWeight(6f);
//				parent.stroke(parent.color(0,255,127));
//				parent.beginShape();
//				parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
//				parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
//				parent.endShape();
				break;

			default:
				break;

			}
			
			break;

		case TYPE_LOOP_WITH_PZERO:
			switch (state) {
			case STATE_DEFAULT:
			
			parent.beginShape();
			parent.strokeWeight(1f); 
			parent.stroke(parent.color(255, 50));
			parent.beginShape();
			parent.vertex(fromNode.getPos().x, fromNode.getPos().y, fromNode.getPos().z);
			parent.stroke(parent.color(40,120,170, 100)); 
			parent.vertex(toNode.getPos().x, toNode.getPos().y, toNode.getPos().z);
			parent.endShape();
			break;
		default:
			break;
			}
		}

		parent.popStyle();
	}

	
	
	
	
	
	public WNode getFromNode() {
		return fromNode;
	}

	public void setFromNode(WNode fromNode) {
		this.fromNode = fromNode;
	}

	public WNode getToNode() {
		return toNode;
	}

	public void setToNode(WNode toNode) {
		this.toNode = toNode;
	}

	@Override
	public String toString() {
		if (type==TYPE_LOOP) {return "WEdge [fromNode=" + fromNode + ", toNode=" + toNode + "]" ;
		} else {
			return "";
		}
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getType() {
		return type;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

}
